/**
 * @class common.datePicker
 * @extends common.base.object
 * 日期选择器
 */
define(function (require) {
    var Base = require('common/base/object');
    require('jqui_extend_timepicker');
    require('jqui_lang_datepicker');
    require('jqui_extend_slideraccess');
    require('jqui_slider');
    require('jqui_datepicker');
    var DATE_PICKER_OPT = {
        showWeek: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',
        showButtonPanel: true,
        timeFormat: 'HH:mm:ss',
        yearRange: '-100:+10',
        stepHour: 1,
        stepMinute: 1,
        stepSecond: 1,
        timeOnlyTitle: '1',
        timeText: '时间',
        hourText: '小时',
        minuteText: '分钟',
        secondText: '秒',
        currentText: '现在',
        closeText: '关闭'
    };

    return Base.extend({
        initialize: function (params) {
            params = params || {};
            _.defaults(params, {wrap: $('.J_date_picker')});
            params.wrap.each(function () {
                var opt = DATE_PICKER_OPT,
                    is_short = $(this).hasClass('date');
                if ($(this).hasClass('time')) {
                    $(this).timepicker(opt);
                    return;
                }
                if ($(this).attr("data-min_date")) {
                    opt.onClose = function (selectedDate) {
                        if (is_short) {
                            $($(this).attr("data-min_date")).datepicker("option", "minDate", selectedDate);
                        } else {
                            $($(this).attr("data-min_date")).datetimepicker("option", "minDate", selectedDate);
                        }
                    };
                }
                if ($(this).attr("data-max_date")) {
                    opt.onClose = function (selectedDate) {
                        if (is_short) {
                            $($(this).attr("data-max_date")).datepicker("option", "maxDate", selectedDate);
                        } else {
                            $($(this).attr("data-max_date")).datetimepicker("option", "maxDate", selectedDate);
                        }
                    };
                }
                if (is_short) {
                    $(this).datepicker(opt);
                } else {
                    $(this).datetimepicker(opt);
                }
            });
        }
    });
});